﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.Revit;
using YJKRevitKernel.RevitObjectSerializeUtility;

namespace YJKRevitDimensionText.AnnotationSetting
{
	public partial class FormAnnotationSetting : System.Windows.Forms.Form
	{
		public FormAnnotationSetting(Autodesk.Revit.DB.Document doc, Transaction trans)
		{
			this.m_doc = doc;
			this.m_trans = trans;
			this.InitializeComponent();
			this.InitTreeView();
			this.RecoveryData();
		}

		public void GetDGVData(Dictionary<string, string> dicFormData, DataGridView dgvAttribute)
		{
            //FormAnnotationSetting.<>c__DisplayClass8_0 <>c__DisplayClass8_ = new FormAnnotationSetting.<>c__DisplayClass8_0();
            //<>c__DisplayClass8_.dgvAttribute = dgvAttribute;
            //int i;
            //int j;
            //for (i = 0; i < <>c__DisplayClass8_.dgvAttribute.Rows.Count; i = j + 1)
            //{
            //    if (<>c__DisplayClass8_.dgvAttribute.Rows[i].Cells[1].Value != null)
            //    {
            //        if (<>c__DisplayClass8_.dgvAttribute.Rows[i].Cells[0].Value.ToString().Contains(TreeViewAndDGVDisplayConstName.ColorName) && !<>c__DisplayClass8_.dgvAttribute.Rows[i].Cells[0].Value.ToString().Contains(TreeViewAndDGVDisplayConstName.GridLineMiddlePart))
            //        {
            //            dicFormData.Add(<>c__DisplayClass8_.dgvAttribute.Rows[i].Cells[0].Value.ToString(), this.m_nColorNum.ToString());
            //        }
            //        else if (TreeViewAndDGVDisplayConstName.BtnTextType.Find((string n) => n.Equals(<>c__DisplayClass8_.dgvAttribute.Rows[i].Cells[0].Value.ToString())) != null)
            //        {
            //            dicFormData.Add(<>c__DisplayClass8_.dgvAttribute.Rows[i].Cells[0].Value.ToString(), this.m_nColorNumGridMid.ToString());
            //        }
            //        else if (TreeViewAndDGVDisplayConstName.NeedSaveComboboxIndexName.Find((string n) => n.Equals(<>c__DisplayClass8_.dgvAttribute.Rows[i].Cells[0].Value.ToString())) != null)
            //        {
            //            int num = ((DataGridViewComboBoxCell)<>c__DisplayClass8_.dgvAttribute.Rows[i].Cells[1]).Items.IndexOf(<>c__DisplayClass8_.dgvAttribute.Rows[i].Cells[1].Value.ToString());
            //            dicFormData.Add(<>c__DisplayClass8_.dgvAttribute.Rows[i].Cells[0].Value.ToString(), num.ToString());
            //        }
            //        else
            //        {
            //            dicFormData.Add(<>c__DisplayClass8_.dgvAttribute.Rows[i].Cells[0].Value.ToString(), <>c__DisplayClass8_.dgvAttribute.Rows[i].Cells[1].Value.ToString());
            //        }
            //    }
            //    j = i;
            //}
		}

		public void SetDGVData(Dictionary<string, string> dicFormData, TreeView treeView)
		{
			TreeNode treeNode = treeView.SelectedNode;
			List<Element> needElements = AnnotationSettingManager.GetNeedElements(this.m_doc, typeof(Autodesk.Revit.DB.ElementType));
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			if (treeNode.Parent.Text == TreeViewAndDGVDisplayConstName.Grid)
			{
				dictionary = SharedParametersConstName.GridParameters;
			}
			else if (treeNode.Parent.Text == TreeViewAndDGVDisplayConstName.Level)
			{
				dictionary = SharedParametersConstName.LevelParameters;
			}
			else if (treeNode.Parent.Text == TreeViewAndDGVDisplayConstName.Profile)
			{
				dictionary = SharedParametersConstName.ProfileParameters;
			}
			else if (treeNode.Parent.Text == TreeViewAndDGVDisplayConstName.AngleTag)
			{
				dictionary = SharedParametersConstName.AngleTagParameters;
			}
			else if (treeNode.Parent.Text == TreeViewAndDGVDisplayConstName.DiameterTag)
			{
				dictionary = SharedParametersConstName.DiameterTagParameters;
			}
			else if (treeNode.Parent.Text == TreeViewAndDGVDisplayConstName.HighProgramPoint)
			{
				dictionary = SharedParametersConstName.DicHighProgramPointTagParameters;
			}
			else if (treeNode.Parent.Text == TreeViewAndDGVDisplayConstName.HighProgramPointLocation)
			{
				dictionary = SharedParametersConstName.HighProgramPointLocaTagParameters;
			}
			else if (treeNode.Parent.Text == TreeViewAndDGVDisplayConstName.HighProgramPointSlope)
			{
				dictionary = SharedParametersConstName.HighProgramPointSlopeTagParameters;
			}
			else if (treeNode.Parent.Text == TreeViewAndDGVDisplayConstName.LineSizeTag)
			{
				dictionary = SharedParametersConstName.SizeTagParameters;
			}
			else if (treeNode.Parent.Text == TreeViewAndDGVDisplayConstName.RadialTag)
			{
				dictionary = SharedParametersConstName.RadiusTagParameters;
			}
			else if (treeNode.Parent.Text == TreeViewAndDGVDisplayConstName.Characters)
			{
				dictionary = SharedParametersConstName.CharactersTagParameters;
			}
			if (treeNode.Parent.Text == TreeViewAndDGVDisplayConstName.Profile)
			{
				Element element = needElements.Find((Element n) => n.Name.Equals(treeNode.Text));
				using (Dictionary<string, string>.Enumerator enumerator = dicFormData.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						KeyValuePair<string, string> item = enumerator.Current;
						try
						{
							Parameter parameter;
							if (TreeViewAndDGVDisplayConstName.LstDetailedIndexMark.Find((string n) => n.Equals(item.Key)) != null)
							{
								parameter = RevitElementExtension.GetParameter(element, TreeViewAndDGVDisplayConstName.DetailedIndexMark);
								if (parameter == null)
								{
									continue;
								}
								ElementId elementId = parameter.AsElementId();
								parameter = RevitElementExtension.GetParameter(this.m_doc.GetElement(elementId), dictionary[item.Key]);
							}
							else if (TreeViewAndDGVDisplayConstName.ProfileDataName.Find((string n) => n.Equals(item.Key)) != null)
							{
								parameter = RevitElementExtension.GetParameter(element, TreeViewAndDGVDisplayConstName.SectionMark);
								if (parameter == null)
								{
									continue;
								}
								ElementId elementId2 = parameter.AsElementId();
								parameter = RevitElementExtension.GetParameter(this.m_doc.GetElement(elementId2), dictionary[item.Key]);
							}
							else
							{
								parameter = RevitElementExtension.GetParameter(element, dictionary[item.Key]);
							}
                            switch ((int)parameter.StorageType)
							{
							case 1:
								parameter.Set(Convert.ToInt32(item.Value));
								break;
							case 2:
							{
								string value = string.Empty;
								if (item.Value.Contains("mm"))
								{
									value = item.Value.Replace("mm", "");
								}
								else
								{
									value = item.Value;
								}
								parameter.Set(AssistFunc.mmToFeet(Convert.ToDouble(value)));
								break;
							}
							case 3:
								parameter.Set(item.Value);
								break;
							case 4:
							{
								if (item.Value.Equals(TreeViewAndDGVDisplayConstName.Null))
								{
									parameter.Set(ElementId.InvalidElementId);
								}
								Element element2 = needElements.Find((Element n) => n.Name.Equals(item.Value));
								if (element2 != null)
								{
									parameter.Set(element2.Id);
								}
								break;
							}
							}
						}
						catch
						{
							YJKMessageBox.Show(item.Key + "参数有误，设置失败");
						}
					}
					return;
				}
			}
			this.SetParaData(dicFormData, treeNode, needElements, dictionary);
		}

		private void RecoveryData()
		{
			SaveOldSelectData data = new SaveOldSelectData();
			Exception ex;
            new HYRevitObjectSerializeManger().TryGetAPersistentClassByXML<SaveOldSelectData>(TreeViewAndDGVDisplayConstName.FilePath, out data, out ex, true);
			if (data == null)
			{
				this.treeViewGridLevelProfile.Nodes[0].ExpandAll();
				if (this.treeViewGridLevelProfile.Nodes.Count > 0)
				{
					TreeNode selectedNode = this.treeViewGridLevelProfile.Nodes[0].Nodes[0];
					this.treeViewGridLevelProfile.SelectedNode = selectedNode;
					this.AnalogMiddleClick();
					return;
				}
			}
			else
			{
				this.tabControl1.SelectTab(data.TabPageNum);
				if (TreeViewAndDGVDisplayConstName.NodeNamePage1.Find((string n) => n.Equals(data.ParentNodeName)) != null)
				{
					this.RecoveryData(data, this.treeViewGridLevelProfile);
					this.AnalogMiddleClick();
					return;
				}
				this.RecoveryData(data, this.treeViewSizeWord);
				this.AnalogMiddleClick();
			}
		}

		private void RecoveryData(SaveOldSelectData data, TreeView treeView)
		{
			foreach (object obj in treeView.Nodes)
			{
				TreeNode treeNode = (TreeNode)obj;
				if (treeNode.ToString().Contains(data.ParentNodeName))
				{
					TreeNode selectedNode = new TreeNode();
					foreach (object obj2 in treeNode.Nodes)
					{
						TreeNode treeNode2 = (TreeNode)obj2;
						if (treeNode2.ToString().Contains(data.ChildNodeName))
						{
							selectedNode = treeNode2;
							treeView.SelectedNode = selectedNode;
							return;
						}
					}
				}
				treeView.Nodes[0].ExpandAll();
				if (treeView.Nodes.Count > 0)
				{
					TreeNode selectedNode2 = treeView.Nodes[0].Nodes[0];
					treeView.SelectedNode = selectedNode2;
				}
			}
		}

		private void AnalogMiddleClick()
		{
			Size size = SystemInformation.WorkingArea.Size;
			int dy = Convert.ToInt32((double)size.Height * 0.48);
			AnalogClicks.MouseMiddleClickEvent(Convert.ToInt32((double)size.Width * 0.4), dy, 0u);
		}

		private void InitTreeView()
		{
			foreach (string text in TreeViewAndDGVDisplayConstName.NodeNamePage1)
			{
				TreeNode treeNode = new TreeNode(text);
				if (text.Equals(TreeViewAndDGVDisplayConstName.Grid))
				{
					this.AddTreeNodeName1(typeof(GridType), treeNode);
				}
				else if (text.Equals(TreeViewAndDGVDisplayConstName.Level))
				{
					this.AddTreeNodeName1(typeof(LevelType), treeNode);
				}
				else if (text.Equals(TreeViewAndDGVDisplayConstName.Profile))
				{
					this.AddTreeNodeName1(typeof(ViewFamilyType), treeNode);
				}
				this.treeViewGridLevelProfile.Nodes.Add(treeNode);
			}
			List<Element> list = (from n in new FilteredElementCollector(this.m_doc).OfClass(typeof(DimensionType))
			select n).ToList<Element>();
			using (List<string>.Enumerator enumerator = TreeViewAndDGVDisplayConstName.NodeNamePage2.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					string nodeName = enumerator.Current;
					TreeNode treeNode2 = new TreeNode(nodeName);
					if (nodeName.Equals(TreeViewAndDGVDisplayConstName.Characters))
					{
						this.AddTreeNodeCharacters(treeNode2);
					}
					else
					{
                        //Predicate<string> <>9__1;
                        //foreach (Element element in list)
                        //{
                        //    Parameter parameter = RevitElementExtension.GetParameter(element, TreeViewAndDGVDisplayConstName.FamilyName);
                        //    if (parameter != null)
                        //    {
                        //        string text2 = parameter.AsString();
                        //        if (text2.Equals(nodeName))
                        //        {
                        //            treeNode2.Nodes.Add(element.Name);
                        //        }
                        //        else
                        //        {
                        //            List<string> lineTagName = TreeViewAndDGVDisplayConstName.LineTagName;
                        //            Predicate<string> match;
                        //            if ((match = <>9__1) == null)
                        //            {
                        //                match = (<>9__1 = ((string n) => n.Equals(nodeName)));
                        //            }
                        //            if (lineTagName.Find(match) != null && text2.Contains(nodeName) && !text2.Equals(element.Name))
                        //            {
                        //                treeNode2.Nodes.Add(element.Name);
                        //            }
                        //        }
                        //    }
                        //}
					}
					this.treeViewSizeWord.Nodes.Add(treeNode2);
				}
			}
		}

		private void AddTreeNodeName1(Type type, TreeNode treeNode)
		{
			foreach (Element element in new FilteredElementCollector(this.m_doc).OfClass(type))
			{
				if (treeNode.Text.Equals(TreeViewAndDGVDisplayConstName.Profile))
				{
					if (RevitElementExtension.GetParameter(element, TreeViewAndDGVDisplayConstName.FamilyName).AsString().Equals(TreeViewAndDGVDisplayConstName.Profile))
					{
						TreeNode treeNode2 = new TreeNode();
						treeNode2.Text = element.Name;
						treeNode.Nodes.Add(treeNode2);
					}
				}
				else
				{
					TreeNode treeNode3 = new TreeNode();
					treeNode3.Text = element.Name;
					treeNode.Nodes.Add(treeNode3);
				}
			}
		}

		private void AddTreeNodeCharacters(TreeNode treeNode)
		{
			foreach (Element element in new FilteredElementCollector(this.m_doc).OfClass(typeof(TextNoteType)))
			{
				treeNode.Nodes.Add(element.Name);
			}
		}

		private void SetSelectColor(TreeNode selectedNode, List<string> lstName, TreeViewCancelEventArgs e)
		{
			if (lstName.Find((string n) => n.Equals(e.Node.Text)) != null)
			{
				e.Cancel = true;
				return;
			}
			if (selectedNode != null)
			{
				selectedNode.BackColor = System.Drawing.Color.Empty;
				selectedNode.ForeColor = System.Drawing.Color.Black;
			}
		}

		private void ShowTypePara1(Type type, TreeNode treeNode)
		{
			Element element = (from n in new FilteredElementCollector(this.m_doc).OfClass(type)
			select n).ToList<Element>().Find((Element n) => n.Name.Equals(treeNode.Text));
			if (element == null)
			{
				return;
			}
			Dictionary<string, string> dic = new Dictionary<string, string>();
			if (treeNode.Parent.Text == TreeViewAndDGVDisplayConstName.Grid)
			{
				dic = SharedParametersConstName.GridParameters;
			}
			else if (treeNode.Parent.Text == TreeViewAndDGVDisplayConstName.Level)
			{
				dic = SharedParametersConstName.LevelParameters;
			}
			else if (treeNode.Parent.Text == TreeViewAndDGVDisplayConstName.Profile)
			{
				dic = SharedParametersConstName.ProfileParameters;
			}
			int nNum = 0;
			if (treeNode.Parent.Text == TreeViewAndDGVDisplayConstName.Profile)
			{
				nNum = this.InitFormDgvProfile(treeNode, element, dic, nNum);
			}
			else
			{
				nNum = this.InitFormDgv1(treeNode, element, dic, nNum);
			}
			this.treeViewGridLevelProfile.SelectedNode = treeNode;
		}

		private int InitFormDgvProfile(TreeNode treeNode, Element selType, Dictionary<string, string> dic, int nNum)
		{
			using (Dictionary<string, string>.Enumerator enumerator = dic.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					KeyValuePair<string, string> item = enumerator.Current;
					try
					{
						DataGridView dataGridView = this.dgvAttribute;
						int rowCount = dataGridView.RowCount;
						dataGridView.RowCount = rowCount + 1;
						this.dgvAttribute.Rows[nNum].Cells[0].Value = item.Key;
						this.SetCellType(nNum, item, this.dgvAttribute);
						string text = string.Empty;
						if (TreeViewAndDGVDisplayConstName.LstDetailedIndexHead.Find((string n) => n.Equals(item.Value)) != null)
						{
							text = this.GetParaData(selType, TreeViewAndDGVDisplayConstName.DetailedIndexMark, item);
							if (text == null)
							{
								continue;
							}
							if (item.Value.Equals(TreeViewAndDGVDisplayConstName.CornerRadius))
							{
								Parameter parameter = RevitElementExtension.GetParameter(selType, TreeViewAndDGVDisplayConstName.DetailedIndexMark);
								if (parameter == null)
								{
									continue;
								}
								ElementId elementId = parameter.AsElementId();
								parameter = RevitElementExtension.GetParameter(this.m_doc.GetElement(elementId), item.Value);
								text = parameter.AsValueString();
							}
							else if (text.Equals(string.Empty))
							{
								text = TreeViewAndDGVDisplayConstName.Null;
							}
						}
						else if (TreeViewAndDGVDisplayConstName.ProfileDataName.Find((string n) => n.Equals(item.Value)) != null)
						{
							text = this.GetParaData(selType, TreeViewAndDGVDisplayConstName.SectionMark, item);
							if (text.Equals(string.Empty))
							{
								text = TreeViewAndDGVDisplayConstName.Null;
							}
						}
						else
						{
							try
							{
								Parameter parameter2 = RevitElementExtension.GetParameter(selType, item.Value);
								text = AnnotationSettingManager.GetParaValue(this.m_doc, parameter2);
							}
							catch
							{
							}
						}
						this.ShowAttributeValue(nNum, item, this.dgvAttribute, text, treeNode);
						nNum++;
					}
					catch
					{
					}
				}
			}
			return nNum;
		}

		private string GetParaData(Element selType, string strName, KeyValuePair<string, string> item)
		{
			Parameter parameter = RevitElementExtension.GetParameter(selType, strName);
			if (parameter == null)
			{
				return null;
			}
			ElementId elementId = parameter.AsElementId();
			parameter = RevitElementExtension.GetParameter(this.m_doc.GetElement(elementId), item.Value);
			if (parameter.AsValueString() != null)
			{
				return parameter.AsValueString();
			}
			return AnnotationSettingManager.GetParaValue(this.m_doc, parameter);
		}

		private int InitFormDgv1(TreeNode treeNode, Element selType, Dictionary<string, string> dic, int nNum)
		{
			try
			{
				this.dgvAttribute.Rows.Clear();
			}
			catch
			{
			}
			foreach (KeyValuePair<string, string> item in dic)
			{
				Parameter parameter = RevitElementExtension.GetParameter(selType, item.Value);
				string empty = string.Empty;
				if (parameter != null && parameter.HasValue)
				{
					DataGridView dataGridView = this.dgvAttribute;
					int rowCount = dataGridView.RowCount;
					dataGridView.RowCount = rowCount + 1;
					this.dgvAttribute.Rows[nNum].Cells[0].Value = item.Key;
					this.SetCellType(nNum, item, this.dgvAttribute);
					if (parameter.AsValueString() == "" || parameter.AsValueString() == null)
					{
						string paraValue = AnnotationSettingManager.GetParaValue(this.m_doc, parameter);
						this.GetLevelHeadName(treeNode, item, ref paraValue);
						try
						{
							this.ShowAttributeValue(nNum, item, this.dgvAttribute, paraValue, treeNode);
							goto IL_10D;
						}
						catch
						{
							continue;
						}
					}
					string strValue = parameter.AsValueString();
					this.GetLevelHeadName(treeNode, item, ref strValue);
					try
					{
						this.ShowAttributeValue(nNum, item, this.dgvAttribute, strValue, treeNode);
					}
					catch
					{
						continue;
					}
					IL_10D:
					nNum++;
				}
			}
			int count = dic.Count;
			while (this.dgvAttribute.Rows.Count > nNum)
			{
				DataGridView dataGridView2 = this.dgvAttribute;
				int rowCount = dataGridView2.RowCount;
				dataGridView2.RowCount = rowCount - 1;
			}
			return nNum;
		}

		private void GetLevelHeadName(TreeNode treeNode, KeyValuePair<string, string> item, ref string strParaValue)
		{
			if (item.Key.Equals(TreeViewAndDGVDisplayConstName.LevelHead))
			{
				foreach (Element element in AnnotationSettingManager.GetNeedElements(this.m_doc, typeof(FamilySymbol)))
				{
					Parameter parameter = RevitElementExtension.GetParameter(element, BuiltInParameter.ELEM_CATEGORY_PARAM);
					if (parameter != null && parameter.AsValueString() != null && !("" == parameter.AsValueString()))
					{
						FamilySymbol familySymbol = element as FamilySymbol;
						if (treeNode.Parent.Text.Equals(TreeViewAndDGVDisplayConstName.Level) && parameter.AsValueString().Contains(TreeViewAndDGVDisplayConstName.Level) && strParaValue.Equals(familySymbol.Name))
						{
							strParaValue = familySymbol.Family.Name + ":" + familySymbol.Name;
							break;
						}
					}
				}
			}
		}

		private void ShowAttributeValue(int nNum, KeyValuePair<string, string> item, DataGridView dgvAttribute, string strValue, TreeNode treeNode)
		{
			if (dgvAttribute.Rows[nNum].Cells[1] is DataGridViewCheckBoxCell)
			{
				if (TreeViewAndDGVDisplayConstName.Chk.Find((string n) => n.Equals(item.Value)) != null)
				{
					DataGridViewCheckBoxCell dataGridViewCheckBoxCell = (DataGridViewCheckBoxCell)dgvAttribute.Rows[nNum].Cells[1];
					if (strValue.Equals("是") || strValue.Equals("1"))
					{
						dataGridViewCheckBoxCell.Value = true;
						return;
					}
				}
			}
			else
			{
				if (dgvAttribute.Rows[nNum].Cells[1] is DataGridViewTextBoxCell)
				{
					dgvAttribute.Rows[nNum].Cells[1].Value = strValue;
					return;
				}
				if (dgvAttribute.Rows[nNum].Cells[1] is DataGridViewImageCell)
				{
					this.InitColor(nNum, item, dgvAttribute, strValue);
					return;
				}
				DataGridViewComboBoxCell dataGridViewComboBoxCell = (DataGridViewComboBoxCell)dgvAttribute.Rows[nNum].Cells[1];
				dataGridViewComboBoxCell.DropDownWidth = 222;
				FormAnnotationSetting.InitCombobox(item, strValue, dataGridViewComboBoxCell, this.m_doc, treeNode);
			}
		}

		private void InitColor(int nNum, KeyValuePair<string, string> item, DataGridView dgvAttribute, string strValue)
		{
			DataGridViewImageCell di = (DataGridViewImageCell)dgvAttribute.Rows[nNum].Cells[1];
			System.Drawing.Color color = this.RGB(Convert.ToInt32(strValue));
			if (TreeViewAndDGVDisplayConstName.BtnTextType.Find((string n) => n.Equals(item.Value)) != null)
			{
				this.m_nColorNumGridMid = this.ParseRGB(color);
			}
			else
			{
				this.m_nColorNum = this.ParseRGB(color);
			}
			string strFilePath;
			this.CreateImageToColor(color, out strFilePath);
			string strContent = string.Concat(new string[]
			{
				"RGB ",
				color.R.ToString(),
				"-",
				color.G.ToString(),
				"-",
				color.B.ToString()
			});
			string strPicturePath;
			this.CreateImageToText(strContent, out strPicturePath, true);
			this.SyntheticPicture(di, color, strFilePath, strPicturePath, true);
		}

		private static void InitCombobox(KeyValuePair<string, string> item, string strValue, DataGridViewComboBoxCell cmbCell, Autodesk.Revit.DB.Document doc, TreeNode treeNode)
		{
			cmbCell.Items.Clear();
			if (TreeViewAndDGVDisplayConstName.LineWidthName.Find((string n) => n.Equals(item.Value)) != null)
			{
				using (List<string>.Enumerator enumerator = TreeViewAndDGVDisplayConstName.LineWidthNum.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						string item2 = enumerator.Current;
						cmbCell.Items.Add(item2);
					}
					goto IL_4ED;
				}
			}
			if (item.Key.Equals(TreeViewAndDGVDisplayConstName.Font))
			{
				using (List<FontFamily>.Enumerator enumerator2 = AnnotationSettingManager.GetAllTypeface().GetEnumerator())
				{
					while (enumerator2.MoveNext())
					{
						FontFamily fontFamily = enumerator2.Current;
						cmbCell.Items.Add(fontFamily.Name);
					}
					goto IL_4ED;
				}
			}
			if (TreeViewAndDGVDisplayConstName.LineType.Find((string n) => n.Equals(item.Value)) != null)
			{
				using (List<Element>.Enumerator enumerator3 = AnnotationSettingManager.GetNeedElements(doc, typeof(LinePatternElement)).GetEnumerator())
				{
					while (enumerator3.MoveNext())
					{
						Element element = enumerator3.Current;
						cmbCell.Items.Add(element.Name);
					}
					goto IL_4ED;
				}
			}
			if (TreeViewAndDGVDisplayConstName.LstArrow.Find((string n) => n.Equals(item.Value)) != null)
			{
				FormAnnotationSetting.AddArrow(cmbCell, doc);
			}
			else if (item.Value.Equals(TreeViewAndDGVDisplayConstName.Symbol))
			{
				FormAnnotationSetting.InitSymbol(cmbCell, doc, treeNode);
			}
			else
			{
				if (item.Value.Equals(TreeViewAndDGVDisplayConstName.TextLocation))
				{
					using (List<string>.Enumerator enumerator = TreeViewAndDGVDisplayConstName.LstTextLocation.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							string item3 = enumerator.Current;
							cmbCell.Items.Add(item3);
						}
						goto IL_4ED;
					}
				}
				if (item.Value.Equals(TreeViewAndDGVDisplayConstName.GridLineMiddlePart))
				{
					using (List<string>.Enumerator enumerator = TreeViewAndDGVDisplayConstName.GridLineMiddlePartStyle.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							string item4 = enumerator.Current;
							cmbCell.Items.Add(item4);
						}
						goto IL_4ED;
					}
				}
				if (item.Value.Equals(TreeViewAndDGVDisplayConstName.NonPlaneViewSymbol))
				{
					using (List<string>.Enumerator enumerator = TreeViewAndDGVDisplayConstName.NonPlaneViewSymbolStyle.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							string item5 = enumerator.Current;
							cmbCell.Items.Add(item5);
						}
						goto IL_4ED;
					}
				}
				if (item.Value.Equals(TreeViewAndDGVDisplayConstName.BasePlaneView))
				{
					using (List<string>.Enumerator enumerator = TreeViewAndDGVDisplayConstName.BasePlane.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							string item6 = enumerator.Current;
							cmbCell.Items.Add(item6);
						}
						goto IL_4ED;
					}
				}
				if (item.Value.Equals(TreeViewAndDGVDisplayConstName.Slope))
				{
					using (List<string>.Enumerator enumerator = TreeViewAndDGVDisplayConstName.LstSlope.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							string item7 = enumerator.Current;
							cmbCell.Items.Add(item7);
						}
						goto IL_4ED;
					}
				}
				if (item.Value.Equals(TreeViewAndDGVDisplayConstName.DisconnectedSectionDisplayStyle))
				{
					using (List<string>.Enumerator enumerator = TreeViewAndDGVDisplayConstName.LstDisconnectedSectionDisplayStyle.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							string item8 = enumerator.Current;
							cmbCell.Items.Add(item8);
						}
						goto IL_4ED;
					}
				}
				if (item.Value.Equals(TreeViewAndDGVDisplayConstName.DetailedIndexHead))
				{
					foreach (Element element2 in AnnotationSettingManager.GetNeedElements(doc, typeof(FamilySymbol)))
					{
						if (RevitElementExtension.GetParameter(element2, TreeViewAndDGVDisplayConstName.FamilyName) != null && RevitElementExtension.GetParameter(element2, TreeViewAndDGVDisplayConstName.FamilyName).AsString().Contains(TreeViewAndDGVDisplayConstName.DetailedIndexHead))
						{
							cmbCell.Items.Add(element2.Name);
						}
					}
					cmbCell.Items.Add(TreeViewAndDGVDisplayConstName.Null);
				}
				else if (item.Value.Contains(TreeViewAndDGVDisplayConstName.Profile) && !item.Value.Equals(TreeViewAndDGVDisplayConstName.DisconnectedSectionDisplayStyle))
				{
					foreach (Element element3 in AnnotationSettingManager.GetNeedElements(doc, typeof(FamilySymbol)))
					{
						if (RevitElementExtension.GetParameter(element3, TreeViewAndDGVDisplayConstName.FamilyName) != null && RevitElementExtension.GetParameter(element3, TreeViewAndDGVDisplayConstName.FamilyName).AsString().Contains(TreeViewAndDGVDisplayConstName.Profile))
						{
							cmbCell.Items.Add(element3.Name);
						}
					}
					cmbCell.Items.Add(TreeViewAndDGVDisplayConstName.Null);
				}
			}
			IL_4ED:
			if (cmbCell.Items.Count > 0)
			{
				try
				{
					bool flag = false;
					if (cmbCell.Items.Contains(strValue))
					{
						flag = true;
						cmbCell.Value = strValue.ToString();
					}
					if (!flag)
					{
						cmbCell.Items.Add(strValue);
						cmbCell.Value = strValue;
					}
				}
				catch
				{
				}
			}
		}

		private static void InitSymbol(DataGridViewComboBoxCell cmbCell, Autodesk.Revit.DB.Document doc, TreeNode treeNode)
		{
			foreach (Element element in AnnotationSettingManager.GetNeedElements(doc, typeof(FamilySymbol)))
			{
				Parameter parameter = RevitElementExtension.GetParameter(element, BuiltInParameter.ELEM_CATEGORY_PARAM);
				if (parameter != null && parameter.AsValueString() != null && !("" == parameter.AsValueString()))
				{
					if (treeNode.Parent.Text.Equals(TreeViewAndDGVDisplayConstName.Grid) && parameter.AsValueString().Contains(TreeViewAndDGVDisplayConstName.Grid))
					{
						cmbCell.Items.Add(element.Name);
					}
					else if (treeNode.Parent.Text.Equals(TreeViewAndDGVDisplayConstName.HighProgramPoint) && parameter.AsValueString().Contains(TreeViewAndDGVDisplayConstName.HighProgramPoint))
					{
						cmbCell.Items.Add(element.Name);
					}
					else if (treeNode.Parent.Text.Equals(TreeViewAndDGVDisplayConstName.HighProgramPointLocation) && parameter.AsValueString().Contains(TreeViewAndDGVDisplayConstName.HighProgramPoint))
					{
						cmbCell.Items.Add(element.Name);
					}
					else if (treeNode.Parent.Text.Equals(TreeViewAndDGVDisplayConstName.Level) && parameter.AsValueString().Contains(TreeViewAndDGVDisplayConstName.Level))
					{
						cmbCell.Items.Add(element.Name);
					}
				}
			}
			cmbCell.Items.Add(TreeViewAndDGVDisplayConstName.Null);
		}

		private static void AddArrow(DataGridViewComboBoxCell cmbCell, Autodesk.Revit.DB.Document doc)
		{
			foreach (Element element in AnnotationSettingManager.GetNeedElements(doc, typeof(Autodesk.Revit.DB.ElementType)))
			{
				if (RevitElementExtension.GetParameter(element, TreeViewAndDGVDisplayConstName.FamilyName) != null)
				{
					string value = RevitElementExtension.GetParameter(element, TreeViewAndDGVDisplayConstName.FamilyName).AsString();
					if (TreeViewAndDGVDisplayConstName.Arrow.Equals(value) && !TreeViewAndDGVDisplayConstName.Arrow.Equals(element.Name))
					{
						cmbCell.Items.Add(element.Name);
					}
				}
				else if (RevitElementExtension.GetParameter(element, TreeViewAndDGVDisplayConstName.LeadLineArrow) != null)
				{
					cmbCell.Items.Add(element.Name);
				}
			}
			cmbCell.Items.Add(TreeViewAndDGVDisplayConstName.Null);
		}

		private void SetCellType(int nNum, KeyValuePair<string, string> item, DataGridView dgvAttribute)
		{
			if (TreeViewAndDGVDisplayConstName.Text.Find((string n) => n.Equals(item.Value)) != null)
			{
				DataGridViewTextBoxCell value = new DataGridViewTextBoxCell();
				dgvAttribute.Rows[nNum].Cells[1] = value;
				return;
			}
			if (TreeViewAndDGVDisplayConstName.BtnImage.Find((string n) => n.Equals(item.Value)) != null)
			{
				DataGridViewImageCell dataGridViewImageCell = new DataGridViewImageCell();
				dgvAttribute.Rows[nNum].Cells[1] = dataGridViewImageCell;
				dataGridViewImageCell.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;
				return;
			}
			if (TreeViewAndDGVDisplayConstName.Chk.Find((string n) => n.Equals(item.Value)) != null)
			{
				DataGridViewCheckBoxCell dataGridViewCheckBoxCell = new DataGridViewCheckBoxCell();
				dgvAttribute.Rows[nNum].Cells[1] = dataGridViewCheckBoxCell;
				dataGridViewCheckBoxCell.Value = false;
				return;
			}
			try
			{
				DataGridViewComboBoxCell dataGridViewComboBoxCell = new DataGridViewComboBoxCell();
				dgvAttribute.Rows[nNum].Cells[1] = dataGridViewComboBoxCell;
				dataGridViewComboBoxCell.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
			}
			catch
			{
			}
		}

		private void CreateImageToColor(ColorDialog colorDia, out System.Drawing.Color color, out string strFilePath)
		{
			color = colorDia.Color;
			Bitmap bitmap = new Bitmap(23, 23);
			Graphics graphics = Graphics.FromImage(bitmap);
			SolidBrush brush = new SolidBrush(color);
			graphics.FillRectangle(brush, new System.Drawing.Rectangle(0, 0, 23, 23));
			string str = color.Name + TreeViewAndDGVDisplayConstName.BMP;
			strFilePath = this.m_strFilePath + "\\" + str;
			if (!Directory.Exists(this.m_strFilePath))
			{
				new DirectoryInfo(this.m_strFilePath).Create();
			}
			if (!File.Exists(strFilePath))
			{
				bitmap.Save(strFilePath);
			}
		}

		private void CreateImageToColor(System.Drawing.Color color, out string strFilePath)
		{
			Bitmap bitmap = new Bitmap(23, 23);
			Graphics graphics = Graphics.FromImage(bitmap);
			SolidBrush brush = new SolidBrush(color);
			graphics.FillRectangle(brush, new System.Drawing.Rectangle(0, 0, 23, 23));
			string str = color.Name + TreeViewAndDGVDisplayConstName.BMP;
			strFilePath = this.m_strFilePath + "\\" + str;
			if (!Directory.Exists(this.m_strFilePath))
			{
				new DirectoryInfo(this.m_strFilePath).Create();
			}
			if (!File.Exists(strFilePath))
			{
				bitmap.Save(strFilePath);
			}
		}

		private int ParseRGB(System.Drawing.Color color)
		{
			return (int)color.B << 16 | (int)((ushort)((int)color.G << 8 | (int)color.R));
		}

		private System.Drawing.Color RGB(int color)
		{
			int red = 255 & color;
			int num = 65280 & color;
			num >>= 8;
			int num2 = 16711680 & color;
			num2 >>= 16;
			return System.Drawing.Color.FromArgb(red, num, num2);
		}

		private void CreateImageToText(string strContent, out string strFilePath, bool bSpecial)
		{
			if (strContent == null || strContent.Trim() == string.Empty)
			{
				strFilePath = string.Empty;
			}
			Bitmap bitmap = new Bitmap(130, 23);
			Graphics graphics = Graphics.FromImage(bitmap);
			string text = string.Empty;
			try
			{
				Font font = new Font("宋体", 10.5f, FontStyle.Regular);
				LinearGradientBrush brush = new LinearGradientBrush(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Color.Black, System.Drawing.Color.Black, 0f);
				graphics.DrawString(strContent, font, brush, 0f, 2.5f);
				if (!Directory.Exists(this.m_strFilePath))
				{
					new DirectoryInfo(this.m_strFilePath).Create();
				}
				text = string.Concat(new string[]
				{
					this.m_strFilePath,
					"\\",
					strContent,
					"0",
					TreeViewAndDGVDisplayConstName.BMP
				});
				if (bSpecial)
				{
					text = string.Concat(new string[]
					{
						this.m_strFilePath,
						"\\",
						strContent,
						"2",
						TreeViewAndDGVDisplayConstName.BMP
					});
				}
				if (!File.Exists(text))
				{
					bitmap.Save(text);
				}
			}
			catch
			{
				graphics.Dispose();
				bitmap.Dispose();
			}
			strFilePath = text;
		}

		private void SetColor(DataGridViewCellEventArgs e, DataGridView dgvAttribute)
		{
			int columnIndex = e.ColumnIndex;
			if (columnIndex == 1)
			{
				int nRow = e.RowIndex;
				if (dgvAttribute.Rows[nRow].Cells[columnIndex] is DataGridViewImageCell)
				{
					DataGridViewImageCell di = (DataGridViewImageCell)dgvAttribute.Rows[nRow].Cells[columnIndex];
					ColorDialog colorDialog = new ColorDialog();
					if (colorDialog.ShowDialog() == DialogResult.OK)
					{
						System.Drawing.Color color;
						string strFilePath;
						this.CreateImageToColor(colorDialog, out color, out strFilePath);
						if (TreeViewAndDGVDisplayConstName.BtnTextType.Find((string n) => n.Equals(dgvAttribute.Rows[nRow].Cells[0].Value.ToString())) != null)
						{
							this.m_nColorNumGridMid = this.ParseRGB(color);
						}
						else
						{
							this.m_nColorNum = this.ParseRGB(color);
						}
						string strContent = string.Concat(new string[]
						{
							"RGB ",
							color.R.ToString(),
							"-",
							color.G.ToString(),
							"-",
							color.B.ToString()
						});
						string strPicturePath;
						this.CreateImageToText(strContent, out strPicturePath, true);
						this.SyntheticPicture(di, color, strFilePath, strPicturePath, true);
					}
				}
			}
		}

		private void SyntheticPicture(DataGridViewImageCell di, System.Drawing.Color color, string strFilePath, string strPicturePath, bool bSpecial)
		{
			Image image = Image.FromFile(strFilePath);
			Image image2 = Image.FromFile(strPicturePath);
			Bitmap bitmap = new Bitmap(image2.Width, image2.Height);
			Graphics graphics = Graphics.FromImage(bitmap);
			graphics.DrawImage(image, 0, 0);
			graphics.DrawImage(image2, image.Width, 0);
			string text = string.Concat(new string[]
			{
				this.m_strFilePath,
				"\\",
				color.Name,
				1.ToString(),
				TreeViewAndDGVDisplayConstName.BMP
			});
			if (bSpecial)
			{
				text = string.Concat(new string[]
				{
					this.m_strFilePath,
					"\\",
					color.Name,
					4.ToString(),
					TreeViewAndDGVDisplayConstName.BMP
				});
			}
			if (!Directory.Exists(this.m_strFilePath))
			{
				new DirectoryInfo(this.m_strFilePath).Create();
			}
			if (!File.Exists(text))
			{
				bitmap.Save(text);
			}
			di.Value = Image.FromFile(text);
		}

		private void CreateNewType(TreeView treeView)
		{
			string text = treeView.SelectedNode.Parent.Text;
			TreeNode parent = treeView.SelectedNode.Parent;
			if (text.Equals(TreeViewAndDGVDisplayConstName.Grid))
			{
				this.CreateNewType(typeof(GridType), this.treeViewGridLevelProfile, parent);
				return;
			}
			if (text.Equals(TreeViewAndDGVDisplayConstName.Level))
			{
				this.CreateNewType(typeof(LevelType), this.treeViewGridLevelProfile, parent);
				return;
			}
			if (text.Equals(TreeViewAndDGVDisplayConstName.Profile))
			{
				this.CreateNewType(typeof(ViewFamilyType), this.treeViewGridLevelProfile, parent);
				return;
			}
			if (text.Equals(TreeViewAndDGVDisplayConstName.Characters))
			{
				this.CreateNewType(typeof(TextNoteType), this.treeViewSizeWord, parent);
				return;
			}
			this.CreateNewType(typeof(DimensionType), this.treeViewSizeWord, parent);
		}

		private void CreateNewType(Type type, TreeView treeView, TreeNode treeNode)
		{
			List<Element> needElements = AnnotationSettingManager.GetNeedElements(this.m_doc, type);
			string strNodeName = treeView.SelectedNode.Text;
			Autodesk.Revit.DB.ElementType elementType = needElements.Find((Element n) => n.Name.Equals(strNodeName)) as Autodesk.Revit.DB.ElementType;
			string[] array = strNodeName.Split(new char[]
			{
				' '
			});
			List<string> list = new List<string>();
			foreach (string item in array)
			{
				list.Add(item);
			}
			int num = 0;
			if (list.Count > 1)
			{
				string value = list[list.Count - 1];
				try
				{
					num = Convert.ToInt32(value);
					list.RemoveAt(list.Count - 1);
				}
				catch (Exception)
				{
				}
			}
			int num2 = 1;
			List<string> list2 = new List<string>();
			foreach (object obj in treeNode.Nodes)
			{
				list2.Add(obj.ToString());
			}
			string strNewName = string.Empty;
			for (;;)
			{
				strNewName = string.Empty;
				foreach (string str in list)
				{
					strNewName = strNewName + " " + str;
				}
				strNewName = strNewName.TrimStart(Array.Empty<char>());
				if (num == 0)
				{
					strNewName = strNewName + " " + (num2 + num + 1).ToString();
				}
				else
				{
					strNewName = strNewName + " " + (num2 + num).ToString();
				}
				if (list2.Find((string n) => n.Contains(strNewName)) == null)
				{
					break;
				}
				num2++;
			}
			elementType.Duplicate(strNewName.Trim());
			TreeNode treeNode2 = new TreeNode();
			treeNode2.Text = strNewName;
			treeNode.Nodes.Add(treeNode2);
			treeView.SelectedNode = treeNode2;
		}

		private void NewSysmbolSort(TreeNode currentNode)
		{
			List<TreeNode> list = new List<TreeNode>();
			foreach (object obj in currentNode.Nodes)
			{
				TreeNode item = (TreeNode)obj;
				list.Add(item);
			}
			List<TreeNode> list2 = (from ff in list
			orderby ff.Text
			select ff).ToList<TreeNode>();
			currentNode.Nodes.Clear();
			foreach (TreeNode node in list2)
			{
				currentNode.Nodes.Add(node);
			}
		}

		private bool NodeReName(NodeLabelEditEventArgs e, TreeView treeView)
		{
			string text = string.Empty;
			if (treeView.SelectedNode == null)
			{
				text = treeView.Nodes[0].Text;
			}
			else
			{
				text = treeView.SelectedNode.Parent.Text;
			}
			Type typeFromHandle;
			if (text.Equals(TreeViewAndDGVDisplayConstName.Grid))
			{
				typeFromHandle = typeof(GridType);
			}
			else if (text.Equals(TreeViewAndDGVDisplayConstName.Level))
			{
				typeFromHandle = typeof(LevelType);
			}
			else if (text.Equals(TreeViewAndDGVDisplayConstName.Profile))
			{
				typeFromHandle = typeof(ViewFamilyType);
			}
			else if (text.Equals(TreeViewAndDGVDisplayConstName.Characters))
			{
				typeFromHandle = typeof(TextNoteType);
			}
			else
			{
				typeFromHandle = typeof(DimensionType);
			}
			List<Element> needElements = AnnotationSettingManager.GetNeedElements(this.m_doc, typeFromHandle);
			Autodesk.Revit.DB.ElementType elementType = needElements.Find((Element n) => n.Name.Equals(this.m_strBeforeNodeName)) as Autodesk.Revit.DB.ElementType;
			try
			{
				if (needElements.Find((Element n) => n.Name.Equals(e.Label)) != null)
				{
					YJKMessageBox.Show("存在相同名字的类型，无法使用此名字，请重新命名");
					e.Node.EndEdit(true);
					treeView.LabelEdit = false;
					return false;
				}
				elementType.Name = e.Label;
				this.m_nSelect = 0;
				e.Node.EndEdit(true);
				treeView.LabelEdit = false;
				this.m_strBeforeNodeName = string.Empty;
				this.m_doc.Regenerate();
			}
			catch (Exception)
			{
				return false;
			}
			return true;
		}

		private void Rename(TreeView treeView)
		{
			treeView.LabelEdit = true;
			TreeNode selectedNode = treeView.SelectedNode;
			this.m_strBeforeNodeName = selectedNode.Text;
			selectedNode.BeginEdit();
			this.m_nSelect = 1;
		}

		private void CancelRename(TreeView treeView, TreeNode treeNode)
		{
			treeView.LabelEdit = false;
			treeNode.EndEdit(true);
			this.m_nSelect = 0;
		}

		private void SetParaData(Dictionary<string, string> dicFormData, TreeNode treeNode, List<Element> lstElements, Dictionary<string, string> dic)
		{
			Element element = null;
			foreach (Element element2 in lstElements)
			{
				if (element2.Name.Equals(treeNode.Text) && RevitElementExtension.GetParameter(element2, TreeViewAndDGVDisplayConstName.FamilyName).AsString().Contains(treeNode.Parent.Text))
				{
					element = element2;
					break;
				}
			}
			using (Dictionary<string, string>.Enumerator enumerator2 = dicFormData.GetEnumerator())
			{
				while (enumerator2.MoveNext())
				{
					KeyValuePair<string, string> item = enumerator2.Current;
					Parameter parameter = RevitElementExtension.GetParameter(element, dic[item.Key]);
					if (parameter != null)
					{
						try
						{
                            switch ((int)parameter.StorageType)
							{
							case 1:
								if (item.Value.Equals("True"))
								{
									parameter.Set(1);
								}
								else if (item.Value.Equals("False"))
								{
									parameter.Set(0);
								}
								else
								{
									parameter.Set(Convert.ToInt32(item.Value));
								}
								break;
							case 2:
								if (item.Key.Equals(TreeViewAndDGVDisplayConstName.WidthCoefficient))
								{
									parameter.Set(Convert.ToDouble(item.Value));
								}
								else
								{
									parameter.Set(AssistFunc.mmToFeet(Convert.ToDouble(item.Value)));
								}
								break;
							case 3:
								parameter.Set(item.Value);
								break;
							case 4:
							{
								if (item.Value.Equals(TreeViewAndDGVDisplayConstName.Null))
								{
									parameter.Set(ElementId.InvalidElementId);
								}
								Element element3 = lstElements.Find((Element n) => n.Name.Equals(item.Value));
								if (element3 != null)
								{
									parameter.Set(element3.Id);
								}
								else
								{
									element3 = AnnotationSettingManager.GetNeedElements(this.m_doc, typeof(LinePatternElement)).Find((Element n) => n.Name.Equals(item.Value));
									if (element3 != null)
									{
										parameter.Set(element3.Id);
									}
									else
									{
										foreach (Element element4 in AnnotationSettingManager.GetNeedElements(this.m_doc, typeof(FamilySymbol)))
										{
											Parameter parameter2 = RevitElementExtension.GetParameter(element, BuiltInParameter.ELEM_CATEGORY_PARAM);
											if (parameter2 != null && parameter2.AsValueString() != null && !("" == parameter.AsValueString()))
											{
												FamilySymbol familySymbol = element4 as FamilySymbol;
												if ((familySymbol.Family.Name + ":" + element4.Name).Equals(item.Value))
												{
													parameter.Set(familySymbol.Id);
													break;
												}
											}
										}
									}
								}
								break;
							}
							}
						}
						catch
						{
							YJKMessageBox.Show(item.Key + "参数有误，设置失败");
						}
					}
				}
			}
		}

		private void DefaultSelectNode()
		{
			if (this.tabPage1.Name == this.tabControl1.SelectedTab.Name)
			{
				this.treeViewGridLevelProfile.Nodes[0].ExpandAll();
				TreeNode selectedNode = this.treeViewGridLevelProfile.Nodes[0].Nodes[0];
				this.treeViewGridLevelProfile.SelectedNode = selectedNode;
				return;
			}
			this.treeViewSizeWord.Nodes[0].ExpandAll();
			TreeNode selectedNode2 = this.treeViewSizeWord.Nodes[0].Nodes[0];
			this.treeViewSizeWord.SelectedNode = selectedNode2;
		}

		private void Rename(NodeLabelEditEventArgs e, TreeView treeView)
		{
			this.CancelRename(treeView, e.Node);
			if (e.Label != null && !this.NodeReName(e, treeView))
			{
				treeView.LabelEdit = true;
				e.Node.BeginEdit();
				this.m_nSelect = 1;
			}
		}

		private void SetLeaveColor(TreeView treeView)
		{
			if (treeView.SelectedNode != null)
			{
				System.Drawing.Color backColor = System.Drawing.Color.FromArgb(0, 150, 255);
				treeView.SelectedNode.BackColor = backColor;
				treeView.SelectedNode.ForeColor = System.Drawing.Color.White;
			}
		}

		private void FormAnnotationSetting_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
			this.dgvAttribute.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
			this.dgvAttribute2.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
		}

		private void treeViewGridLevelProfile_BeforeSelect(object sender, TreeViewCancelEventArgs e)
		{
			this.SetSelectColor(this.treeViewGridLevelProfile.SelectedNode, TreeViewAndDGVDisplayConstName.NodeNamePage1, e);
		}

		private void treeViewSizeWord_BeforeSelect(object sender, TreeViewCancelEventArgs e)
		{
			this.SetSelectColor(this.treeViewSizeWord.SelectedNode, TreeViewAndDGVDisplayConstName.NodeNamePage2, e);
		}

		private void FormAnnotationSetting_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '\u001b')
			{
				base.Close();
			}
		}

		private void treeViewGridLevelProfile_AfterSelect(object sender, TreeViewEventArgs e)
		{
			TreeNode selectedNode = this.treeViewGridLevelProfile.SelectedNode;
			string text = selectedNode.Parent.Text;
			this.dgvAttribute.Rows.Clear();
			if (text == TreeViewAndDGVDisplayConstName.Grid)
			{
				this.ShowTypePara1(typeof(GridType), selectedNode);
				return;
			}
			if (text == TreeViewAndDGVDisplayConstName.Level)
			{
				this.ShowTypePara1(typeof(LevelType), selectedNode);
				return;
			}
			if (text == TreeViewAndDGVDisplayConstName.Profile)
			{
				this.ShowTypePara1(typeof(ViewFamilyType), selectedNode);
			}
		}

		private void treeViewSizeWord_AfterSelect(object sender, TreeViewEventArgs e)
		{
			TreeNode selectNode = this.treeViewSizeWord.SelectedNode;
			this.dgvAttribute2.Rows.Clear();
			List<Element> list = (from n in new FilteredElementCollector(this.m_doc).OfClass(typeof(DimensionType))
			select n).ToList<Element>();
			Autodesk.Revit.DB.ElementType elementType = null;
			foreach (Element element in list)
			{
				if (element.Name.Equals(selectNode.Text))
				{
					Parameter parameter = RevitElementExtension.GetParameter(element, TreeViewAndDGVDisplayConstName.FamilyName);
					if (parameter == null)
					{
						return;
					}
					if (parameter.AsString().Contains(selectNode.Parent.Text))
					{
						elementType = (element as DimensionType);
						break;
					}
				}
			}
			if (selectNode.Parent.Text.Equals(TreeViewAndDGVDisplayConstName.Characters))
			{
				List<Element> list2 = (from n in new FilteredElementCollector(this.m_doc).OfClass(typeof(TextNoteType))
				select n).ToList<Element>();
				if (list2.Find((Element n) => n.Name.Equals(selectNode.Text)) == null)
				{
					return;
				}
				elementType = (list2.Find((Element n) => n.Name.Equals(selectNode.Text)) as TextNoteType);
			}
			if (elementType == null)
			{
				return;
			}
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			if (selectNode.Parent.Text == TreeViewAndDGVDisplayConstName.AngleTag)
			{
				dictionary = SharedParametersConstName.AngleTagParameters;
			}
			else if (selectNode.Parent.Text == TreeViewAndDGVDisplayConstName.DiameterTag)
			{
				dictionary = SharedParametersConstName.DiameterTagParameters;
			}
			else if (selectNode.Parent.Text == TreeViewAndDGVDisplayConstName.HighProgramPoint)
			{
				dictionary = SharedParametersConstName.DicHighProgramPointTagParameters;
			}
			else if (selectNode.Parent.Text == TreeViewAndDGVDisplayConstName.HighProgramPointLocation)
			{
				dictionary = SharedParametersConstName.HighProgramPointLocaTagParameters;
			}
			else if (selectNode.Parent.Text == TreeViewAndDGVDisplayConstName.HighProgramPointSlope)
			{
				dictionary = SharedParametersConstName.HighProgramPointSlopeTagParameters;
			}
			else if (selectNode.Parent.Text == TreeViewAndDGVDisplayConstName.LineSizeTag)
			{
				dictionary = SharedParametersConstName.SizeTagParameters;
			}
			else if (selectNode.Parent.Text == TreeViewAndDGVDisplayConstName.RadialTag)
			{
				dictionary = SharedParametersConstName.RadiusTagParameters;
			}
			else if (selectNode.Parent.Text == TreeViewAndDGVDisplayConstName.Characters)
			{
				dictionary = SharedParametersConstName.CharactersTagParameters;
			}
			int num = 0;
			using (Dictionary<string, string>.Enumerator enumerator2 = dictionary.GetEnumerator())
			{
				while (enumerator2.MoveNext())
				{
					KeyValuePair<string, string> item = enumerator2.Current;
					if (item.Key.Equals(TreeViewAndDGVDisplayConstName.SizeCharacters) || item.Key.Equals(TreeViewAndDGVDisplayConstName.SizeLine))
					{
						DataGridView dataGridView = this.dgvAttribute2;
						int rowCount = dataGridView.RowCount;
						dataGridView.RowCount = rowCount + 1;
						this.dgvAttribute2.Rows[num].Cells[0].Value = item.Key;
						this.dgvAttribute2.Rows[num].DefaultCellStyle.BackColor = System.Drawing.Color.Gray;
						this.dgvAttribute2.Rows[num].ReadOnly = true;
						num++;
					}
					else
					{
						Parameter parameter2 = RevitElementExtension.GetParameter(elementType, item.Value);
						string empty = string.Empty;
						if (parameter2 != null && parameter2.HasValue)
						{
							DataGridView dataGridView2 = this.dgvAttribute2;
							int rowCount = dataGridView2.RowCount;
							dataGridView2.RowCount = rowCount + 1;
							this.SetCellType(num, item, this.dgvAttribute2);
							this.dgvAttribute2.Rows[num].Cells[0].Value = item.Key;
							if (parameter2.AsValueString() == "" || parameter2.AsValueString() == null)
							{
								string text = AnnotationSettingManager.GetParaValue(this.m_doc, parameter2);
								if (!(this.dgvAttribute2.Rows[num].Cells[1] is DataGridViewComboBoxCell) && text.Contains("mm"))
								{
									text = text.Replace("mm", "");
								}
								try
								{
									this.ShowAttributeValue(num, item, this.dgvAttribute2, text, selectNode);
									goto IL_516;
								}
								catch
								{
									continue;
								}
							}
							string text2 = parameter2.AsValueString();
							if (!(this.dgvAttribute2.Rows[num].Cells[1] is DataGridViewComboBoxCell) && text2.Contains("mm"))
							{
								text2 = text2.Replace("mm", "");
							}
							try
							{
								this.ShowAttributeValue(num, item, this.dgvAttribute2, text2, selectNode);
							}
							catch
							{
								continue;
							}
							IL_516:
							if (SharedParametersConstName.NeedCompanyName.Find((string n) => n.Equals(item.Key)) != null)
							{
								this.dgvAttribute2.Rows[num].Cells[2].Value = "mm";
							}
							num++;
						}
					}
				}
			}
		}

		private void dgvAttribute2_CellClick(object sender, DataGridViewCellEventArgs e)
		{
			this.SetColor(e, this.dgvAttribute2);
		}

		private void dgvAttribute_CellClick(object sender, DataGridViewCellEventArgs e)
		{
			this.SetColor(e, this.dgvAttribute);
		}

		private void dgvAttribute_CellEndEdit(object sender, DataGridViewCellEventArgs e)
		{
			int columnIndex = e.ColumnIndex;
			if (columnIndex == 1)
			{
				int rowIndex = e.RowIndex;
				if (this.dgvAttribute.Rows[rowIndex].Cells[columnIndex] is DataGridViewComboBoxCell)
				{
					DataGridViewComboBoxCell dataGridViewComboBoxCell = (DataGridViewComboBoxCell)this.dgvAttribute.Rows[rowIndex].Cells[columnIndex];
					if (this.dgvAttribute.Rows[rowIndex].Cells[0].Value.ToString().Contains(TreeViewAndDGVDisplayConstName.GridLineMiddlePart))
					{
						int num = dataGridViewComboBoxCell.Items.IndexOf(this.dgvAttribute.Rows[rowIndex].Cells[columnIndex].Value);
						RevitElementExtension.GetParameter((from n in new FilteredElementCollector(this.m_doc).OfClass(typeof(GridType))
						select n).ToList<Element>().Find((Element n) => n.Name.Equals(this.treeViewGridLevelProfile.SelectedNode.Text)), TreeViewAndDGVDisplayConstName.GridLineMiddlePart).Set(num);
						this.m_doc.Regenerate();
						this.ShowTypePara1(typeof(GridType), this.treeViewGridLevelProfile.SelectedNode);
					}
				}
			}
		}

		private void btnCopy2_Click(object sender, EventArgs e)
		{
			this.CreateNewType(this.treeViewSizeWord);
		}

		private void btnCopy_Click(object sender, EventArgs e)
		{
			this.CreateNewType(this.treeViewGridLevelProfile);
		}

		private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.DefaultSelectNode();
		}

		private void btnRename_Click(object sender, EventArgs e)
		{
			this.Rename(this.treeViewGridLevelProfile);
		}

		private void btnRename2_Click(object sender, EventArgs e)
		{
			this.Rename(this.treeViewSizeWord);
		}

		private void treeViewSizeWord_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
		{
			if (this.m_nSelect == 1)
			{
				this.Rename(e, this.treeViewSizeWord);
				this.m_nSelect = 0;
			}
		}

		private void treeViewGridLevelProfile_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
		{
			if (this.m_nSelect == 1)
			{
				this.Rename(e, this.treeViewGridLevelProfile);
				this.m_nSelect = 0;
				return;
			}
			if (this.m_nSelect == 0 && e.Label == null)
			{
				this.treeViewGridLevelProfile.LabelEdit = true;
				e.Node.BeginEdit();
			}
		}

		private void treeViewGridLevelProfile_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.F2)
			{
				this.Rename(this.treeViewGridLevelProfile);
			}
		}

		private void treeViewSizeWord_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.F2)
			{
				this.Rename(this.treeViewSizeWord);
			}
		}

		private void btnApplication_Click(object sender, EventArgs e)
		{
			Dictionary<string, string> dicFormData = new Dictionary<string, string>();
			if (this.tabPage1.Name == this.tabControl1.SelectedTab.Name)
			{
				this.GetDGVData(dicFormData, this.dgvAttribute);
				this.SetDGVData(dicFormData, this.treeViewGridLevelProfile);
				if (this.m_trans.HasStarted())
				{
					this.m_trans.Commit();
					this.m_trans.Start();
					return;
				}
			}
			else
			{
				this.GetDGVData(dicFormData, this.dgvAttribute2);
				this.SetDGVData(dicFormData, this.treeViewSizeWord);
				if (this.m_trans.HasStarted())
				{
					this.m_trans.Commit();
					this.m_trans.Start();
				}
			}
		}

		private void treeViewGridLevelProfile_Leave(object sender, EventArgs e)
		{
			this.SetLeaveColor(this.treeViewGridLevelProfile);
		}

		private void treeViewSizeWord_Leave(object sender, EventArgs e)
		{
			this.SetLeaveColor(this.treeViewSizeWord);
		}

		private Document m_doc;

		private string m_strFilePath = Product.UserDataLocation + "ColorPicture";

		private string m_strBeforeNodeName = string.Empty;

		private int m_nColorNum;

		private int m_nColorNumGridMid;

		private int m_nSelect;

		private Transaction m_trans;
	}
}
